package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select *from setmeal where id=#{id}")
    Setmeal getSetmealById(long id);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 新增套餐
     * @param setmeal
     */
    @Update("insert into setmeal(category_id,name,price,status,description,image,create_time,update_time,create_user,update_user)"+
            " values(#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addSetmeal(Setmeal setmeal);

    /**
     * 修改套餐状态
     * @param setmeal
     */
    @Update("update setmeal set status = #{status},update_time = #{updateTime},update_user = #{updateUser} where id = #{id}")
    void changeStatus(Setmeal setmeal);

    /**
     * 批量删除
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 修改套餐
     * @param setmeal
     */
    @Update("update setmeal set category_id = #{categoryId},name = #{name},price = #{price},status = #{status},description = #{description}," +
            "image = #{image},update_time = #{updateTime},update_user = #{updateUser} where id = #{id}")
    void editSetmeal(Setmeal setmeal);

    /**
     *根据套餐的名字查询
     */
    @Select("select * from setmeal where name = #{name}")
    Setmeal getSetmealByName(String name);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
